<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <label class="el-form-item-label">入库任务编号</label>
        <el-input v-model.trim="query.inboundTaskNo" clearable placeholder="入库任务编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" @clear="crud.toQuery" />
        <!-- <label class="el-form-item-label">入库单号</label>
        <el-input v-model="query.inboundOrderNo" clearable placeholder="入库单号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">入库任务状态</label>
        <el-input v-model="query.status" clearable placeholder="入库任务状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <rrOperation :crud="crud" />
      </div>
      <crudOperation :permission="permission">
        <!-- <template slot="right">
          <el-upload
            ref="uploadRef"
            slot="right"
            class="filter-item"
            :headers="headers"
            :action="uploadUrl"
            :limit="1"
            :show-file-list="false"
            :http-request="customUpload"
          >
            <el-button
              type="success"
              plain
              icon="el-icon-upload2"
              size="mini"
              @click="handleUpload"
            >导入</el-button>
          </el-upload>
        </template> -->
      </crudOperation>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <!-- <el-table-column type="selection" width="55" /> -->
        <el-table-column prop="inboundTaskNo" label="入库任务编号" />
        <el-table-column prop="inboundOrderNo" label="入库单号" />
        <el-table-column prop="taskType" label="入库任务类型" />
        <el-table-column prop="status" label="入库任务状态">
          <template slot-scope="scope">
            {{ dict.label.allOrder_status[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column prop="priority" label="优先级" />
        <el-table-column prop="createTime" label="创建时间" />
        <el-table-column prop="finishTime" label="完成时间" />
        <el-table-column prop="taskStart" label="任务起点" />
        <el-table-column prop="taskEnd" label="任务终点" />
        <el-table-column prop="parentPalletCode" label="母托编码" />
        <el-table-column prop="bandingForInbound" label="入库是否打带" />
        <el-table-column prop="bandingType" label="打带类型（1-双根打带，2-四根打带，99-不打带）" />
        <el-table-column label="裹膜圈数">
          <template slot-scope="scope">
            {{ scope.row.wrappingQty === 0 ? '不用裹膜' : scope.row.wrappingQty }}
          </template>
        </el-table-column>
        <!-- <el-table-column v-if="checkPer(['admin','inboundTaskHistory:edit','inboundTaskHistory:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import { getToken } from '@/utils/auth'
import crudInboundTaskHistory from '@/api/work/inboundMissionHistory'
import { uploadFileAPI } from '@/api/work/inboundMissionHistory'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, inboundTaskNo: null, inboundOrderNo: null, taskType: null, status: null, priority: null, createTime: null, finishTime: null, taskStart: null, taskEnd: null, parentPalletCode: null, bandingForInbound: null, bandingType: null, wrappingQty: null }
export default {
  name: 'InboundMissionHistory',
  components: { pagination, rrOperation, crudOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['allOrder_status'],
  cruds() {
    return CRUD({ title: '1', url: 'api/inboundTaskHistory', idField: 'id', sort: 'id,desc', crudMethod: { ...crudInboundTaskHistory },
      optShow: {
        add: false,
        edit: false,
        del: false,
        reset: true,
        download: true
      }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'inboundTaskHistory:add', 'otherUser'],
        edit: ['admin', 'inboundTaskHistory:edit', 'otherUser'],
        del: ['admin', 'inboundTaskHistory:del', 'otherUser']
      },
      rules: {
      },
      queryTypeOptions: [
        { key: 'inboundTaskNo', display_name: '入库任务编号' },
        { key: 'inboundOrderNo', display_name: '入库单号' },
        { key: 'status', display_name: '入库任务状态' }
      ],
      uploadUrl: process.env.VUE_APP_BASE_API + '',
      headers: {
        'Authorization': getToken(),
        'Content-Type': 'multipart/form-data'
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    async customUpload(file) {
      const formData = new FormData()
      formData.append('file', file.file)
      const res = await uploadFileAPI({
        formData: formData,
        ruleType: this.selectedValue
      })
      if (res.result === 'OK') {
        this.$message.success(res.data)
      } else {
        this.$message.warning(res.data)
      }
    },
    // 清除已选择的文件
    handleUpload() {
      this.$refs.uploadRef.clearFiles() // 清除已选择的文件
      this.$refs.uploadRef.submit() // 重新提交上传
    }
  }
}
</script>

<style scoped>

</style>
